package com.yoyo.yyadsdk.util;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class DownIconBitmap {
    public static synchronized Bitmap downloadPushIcon(String downloadurl) {
        Bitmap bitmap = null;
        InputStream is = null;
        BufferedInputStream bis = null;
        try {
            if (!TextUtils.isEmpty(downloadurl)
            ) {
                int nReadlen = 0;
                // File fileFolder = new File(dstDir);
                /*
                 * if (!fileFolder.exists()) { fileFolder.mkdirs(); }
                 */
                URL url = new URL(downloadurl);

                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setConnectTimeout(6000);
                conn.setReadTimeout(6000);
                conn.connect();
                int length = conn.getContentLength();
                //	String strContentType = conn.getHeaderField("Content-Type");
                if (conn.getResponseCode() == 200) {
                    is = conn.getInputStream();
                    bis = new BufferedInputStream(is, length);
                    bitmap = BitmapFactory.decodeStream(is);
                    conn.disconnect();
                }
            }
        } catch (Exception ignored) {
        } finally {
            try {

                if (bis != null) {
                    bis.close();
                }
                if (is != null) {
                    is.close();
                }
            } catch (IOException ignored) {
            }
        }
        return bitmap;
    }
}
